import 'package:flutter_ncsjqz_getx/http/dio_service.dart';
import 'package:flutter_ncsjqz_getx/model/base_entity.dart';
import 'package:flutter_ncsjqz_getx/model/platform_msg_entity.dart';
import 'package:flutter_ncsjqz_getx/model/sys_notice_entity.dart';
import 'package:flutter_ncsjqz_getx/util/toast_util.dart';
import 'package:get/get.dart';

class MessageInfoLogic extends GetxController {
  List<SysNoticeData>? sysNoticeData = [SysNoticeData()..msgTitle=''..redDot=false];
  List<PlatformMsgDataList>? msgList = [PlatformMsgDataList()];
  int currPage = 0;
  /// 获取系统公告
  getSysNotice() async{
    SysNoticeEntity sysNoticeEntity = await DioService<SysNoticeEntity>().v2_listSysNotice();
    sysNoticeData = sysNoticeEntity.data;
    update();
  }

  /// 获取平台、评论消息
  getPtAndPlMessage(msgType,{bool load:false}) async{
    if(load){
      currPage++;
    }else{
      currPage = 0;
    }
    PlatformMsgEntity platformMsgEntity1 = await DioService<PlatformMsgEntity>().messagePage({
      "pageSize": 25,
      "currPage": currPage,
      "msgType": msgType,
    });
    if(platformMsgEntity1.code==0 && platformMsgEntity1.data!=null && platformMsgEntity1.data!.xList!.length >0){
      if(load){
        msgList!.addAll(platformMsgEntity1.data!.xList!);
        print("第$currPage页");
      }else{
        msgList = platformMsgEntity1.data!.xList;
      }
    }
    update();
  }

  /// 关注
  setFollow(followUserId) async{
    BaseEntity baseEntity = await DioService<BaseEntity>().clickFollow({
      "beFollowUserId": followUserId,
    });
    if(baseEntity.code == 0){
      toast("关注成功");
      update();
    }
  }
}
